package util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import cai.Config;
import cai.ssq.TaoBaoSSQ;

public class FileUtil {
	public final static String uploadPath = "upload";// 上传文件路径

	/**
	 * 流写入文件
	 * **/
	public static boolean inputStreamToFile(InputStream ins, File file) {
		OutputStream os;
		try {
			os = new FileOutputStream(file);
			int bytesRead = 0;
			byte[] buffer = new byte[8192];
			while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
				os.write(buffer, 0, bytesRead);
			}
			os.close();
			ins.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 从指定位置文件中一行一行读取内容并把每行存入List集合
	 * */
	public static List readInputByRow(String path) {
		List list = new ArrayList();
		File file = new File(path);
		try {
			FileInputStream fis = new FileInputStream(file);
			InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
			BufferedReader reader = new BufferedReader(isr);
			String tempstring = "";
			while ((tempstring = reader.readLine()) != null) {
				list.add(tempstring);
			}
			reader.close();
			isr.close();
			fis.close();
			return list;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static void main(String[] args) {
//		List list=FileUtil.readInputByRow(Config.getInstance().sendMailBCCFile);
	}
}
